home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d2
/
stayres.arc
/
STAYRSTR.340
< prev
next >
Wrap
Text File
|
1988-06-27
|
7KB
|
116 lines
{****************************************************************************}
{ S T A Y R S T R . I N C }
{ }
{ This is the StayRstr.Inc file included above }
{ Separate the code out into a file or replace the $I StayRstr.331 }
{ statement above with this code. }
{****************************************************************************}
{Version 3.31}
{ Inline Code to restore the stack and regs moved}
{ to the Turbo Resident Stack which allows }
{ re-entrancy into Dos for I/O and recursion }
{ for Turbo Terminate & Stay Resident programs. }
{ Author: Lane Ferris }
{ - The Hunter's Helper - }
{ Distributed to the Public Domain for use without profit. }
{ Original Version 5.15.85 }
{----------------------------------------------------------------------}
{ Restore the Dos (or interrupted pgm) Regs and Stack }
{----------------------------------------------------------------------}
{ On entry the Stack will already contain: }
{ Pointer to bottom of stack }
{ Bottom of Dos Stack Ptr }
{ StackSize words of saved pgm stack }
{ Dos Flags }
{ Dos Code Segment }
{ Dos Instruction Ptr }
{ Dos Base Pointer }
{ Dos Original Stack Ptr }
{ Retrieve the Regpack registers as they were }
{ stored for the Interrupt Entry. }
inline(
$BD/Regs/ {Mov Bp,offset REGS}
$2E/$8B/$46/$00/ {CS:Mov Ax,[Bp+0]}
$2E/$8B/$5E/$02/ {Cs:Mov Bx,[Bp+2]}
$2E/$8B/$4E/$04/ {CS:Mov Cx,[Bp+4]}
$2E/$8B/$56/$06/ {CS:Mov Dx,[Bp+6]}
$2E/$8B/$76/$0A/ {CS:Mov Si,[Bp+A]}
$2E/$8B/$7E/$0C/ {CS:Mov Di,[Bp+C]}
$2E/$8E/$5E/$0E/ {CS:Mov DS,[Bp+E]}
$2E/$8E/$46/$10/ {CS:Mov ES,[Bp+10]}
$2E/$FF/$76/$12/ {Push Cs:[Bp+12] }
{PopF }
{ The following code was added to avoid }
{ the 80286 Pop flag (POPF) bug which }
{ enables interrupts while we are trying}
{ to POP the stack on odd byte boundry }
$EB/$01/ {JMP $+3 Skip over IRET }
$CF/ {IRET POP IP/CS/Flags }
$0E/ {PUSH CS Make a return }
$E8/$FB/$FF/ {CALL CS:$-2 Pop the Flags}
{ If [Cs:InUse]:= True, then dont restore the stack.}
{ This program is being recursive. Else restore Dos }
{ Stack and Program Entry registers for final exit. }
$2E/$80/$3E/Inuse/$01/ {Cmp byte ptr Cs:[Inuse],1 }
$74/$25/ {Je ReCurOut J-U-M-P }
{ Move "StackSize" words back to the interrupted pgms}
{ stack. The originals could have been clobber by our}
{ being recursive. (Especially true of DOS) }
$FA / { Cli ; Stop all interrupts }
$5E/ {Pop Si Bottom of Dos Stack }
$2E/$8B/$0E/StackSize/ {Mov Cx,Cs:StackSize Saved Stack Words }
$2E/$8E/$06/DosSSeg/ {Mov ES,Cs:DosSSeg Get Dos StackSegment }
{Restack:}
$4E/$4E/ {Dec Si/Dec Si Backup Dos Stack }
$26/$8F/$04/ {Pop Es:[Si] Dos Stack := Our Stack }
$E2/$F9/ {Loop to Restack }
$89/$F5/ {Mov Bp,Si Save Dos Sp across Pops }
{ - C - A - U - T - I - O - N - }
{ Restore the original interrupted programs regs }
{ except Ax. Ax usually contains status. It contains }
{ a scan code and key for Int 16. You may want to }
{ rework this if using another interrupt. }
$07/ {Pop Es }
$1F/ {Pop Ds }
$5F/ {Pop Di }
$5E/ {Pop Si }
$5A/ {Pop Dx }
$59/ {Pop Cx }
$5B/ {Pop Bx }
$44/$44/ {Inc sp/Inc sp Thow old Ax value away }
$89/$EC/ {Mov Sp,Bp Setup Dos Stack Ptr }
$2E/$8E/$16/DosSSeg/ {Mov SS,Cs:DosSSeg Give back Dos Stack }
{RecurOut} {Clean up the Stack }
$5D/ {Pop Bp Throw away old dos Sp }
$BD/Regs/ {Mov Bp,offset REGS }
$2E/$FF/$76/$12/ {Push Cs:[Bp+12] Flags from last }
{PopF interrupt. }
{ The following code was added to avoid }
{ the 80286 Pop flag (POPF) bug which }
{ enables interrupts while we are trying }
{ to POP the stack on odd byte boundry }
$EB/$01/ {JMP $+3 Skip over IRET }
$CF/ {IRET POP IP/CS/Flags }
$0E/ {PUSH CS Make a return }
$E8/$FB/$FF/ {CALL CS:$-2 Pop the Flags}
$5D/ {Pop Bp Retrieve old BP }
$FB/ {Sti Enable interrupts }
$CA/$02/$00 {Ret Far 002 Thow old flags away}
);
{.......................................................................}